/**
 * Created by Abe on 2017/3/10.
 */
(function() {
    'use strict';

    angular
        .module('zhserverApp')
        .controller('DoctorManageController', DoctorManageController);

    DoctorManageController.$inject = ['DoctorManage','AlertService','Doctor'];

    function DoctorManageController (DoctorManage,AlertService,Doctor) {
        var vm = this;
        vm.loadAll=loadAll;
        vm.pass=pass;
        vm.refuse=refuse;
        vm.loadAll();


        function loadAll () {
            DoctorManage.query({
            }, onSuccess, onError);
            function onSuccess(data) {
                vm.doctors = data;
            }
            function onError(error) {
                AlertService.error(error.data.message);
            }
        }
        function pass(doctor) {
            doctor.flag=true;
            Doctor.update(doctor,function () {
                alert("通过成功");
            } ,function () {
                alert("通过失败，请重新尝试！");
            });
                $state.go('zhManage', null, { reload: 'zhManage' });
        }
        function refuse(id) {
            Doctor.delete({id: id},
                function () {
                    alert("拒绝成功！");
                    $state.go('zhManage', null, { reload: 'zhManage' });
                },function () {
                    alert("拒绝失败，请重新尝试！");
                });
        }
    }
})();
